package com.sicheng.蓝桥.练习题;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;

import static com.sicheng.蓝桥.练习题.蓝桥.gcd;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/4/8 15:01
 */
public class 直线 {
    /**
     * https://blog.csdn.net/qq_59700927/article/details/122892403
     * (20*21个整点), 0<=x<20, 0<=y<21
     * <p>
     * <p>
     * (x2-x1)y-(y2-y1)x=y1x2-y2x1
     */

    static class Point {
        int x;
        int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    static class Line {
        int a;
        int b;
        int c;

        public Line(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Line line = (Line) o;
            return a == line.a && b == line.b && c == line.c;
        }

        @Override
        public int hashCode() {
            return Objects.hash(a, b, c);
        }
    }

    public static void main(String[] args) {
//        System.out.println(-2%(2));
        ArrayList<Point> list = new ArrayList<>();
        for (int y = 0; y < 21; y++) {
            for (int x = 0; x < 20; x++) {
                list.add(new Point(x, y));
            }
        }
        HashSet<Line> line = new HashSet<>();

        for (int i = 0; i < list.size(); i++) {
            for (int j = i + 1; j < list.size(); j++) {
                Point s1 = list.get(i);
                Point s2 = list.get(j);
                //x2-x1
                int a = s2.x - s1.x;
                int b = s2.y - s1.y;
                //y1x2-y2x1
                int c = s1.y * s2.x - s2.y * s1.x;
                int gcd = gcd(a, gcd(b, c));
                line.add(new Line(a / gcd, b / gcd, c / gcd));

            }
        }
        System.out.println(line.size());
    }

    @Test
    public void test() {
        int i = gcd(6, -3);
        int j = gcd(-3, 6);
        int k =gcd(2,-32);
        int m =gcd(-32,2);
        System.out.println(gcd(i, -3));

    }
}
